package cn.wolfcode.shop.mq;

import cn.wolfcode.shop.result.CodeMsg;
import cn.wolfcode.shop.service.IWebSocketService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;

@Component
public class MQReceiver {
    @Autowired
    private JmsTemplate jmsTemplate;
    @Autowired
    private IWebSocketService webSocketService;
    @JmsListener(destination = MQDestination.WEBSOCKET_QUEUE)
    public void receiverMsg(Message message) throws JMSException {
        if(message instanceof MapMessage){
            MapMessage mapMessage = (MapMessage) message;
            String uuid = mapMessage.getString("uuid");
            String codeMsg = mapMessage.getString("codeMsg");
            webSocketService.sendWebsocketMsg(uuid,codeMsg);
        }
    }
}
